package com.ctshk.rpc.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ctshk.rpc.system.dto.AreaHasChildrenDTO;
import com.ctshk.rpc.system.entity.SysArea;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author 谢诗宏
 * @since 2021-01-11
 */
public interface SysAreaMapper extends BaseMapper<SysArea> {

    @Select("SELECT a.id,a.status,a.country_code code,a.country_pinyin,a.country_traditional name,(SELECT count(0) > 0 FROM t_sys_area t \n" +
            "WHERE t.is_deleted = #{isDelete} AND t.`level` = #{levelTwo} AND t.parent_id = a.id ) has_children \n" +
            "FROM t_sys_area a WHERE ( a.is_deleted = #{isDelete} AND a.`level` = #{levelOne} ) ")
    List<AreaHasChildrenDTO> getOneLevelArea(
            @Param("isDelete") Integer isDelete,
            @Param("levelOne") Integer levelOne,
            @Param("levelTwo") Integer levelTwo);
}
